﻿using Abp;
using System;
using System.Collections.Generic;
using System.Text;
using WebApiClient.DataAnnotations;

namespace ARchGL.Platform.FileServer
{
    public class AjaxResponse<TResult>
    {
        public AjaxResponse()
        {
        }

        /// <summary>
        /// 接口执行结果代码，返回“200”时表示执行成功
        /// </summary>
        [AliasAs("total")]
        public int Total { get; set; }
        [AliasAs("code")]
        public int Code { get; set; }
        [AliasAs("success")]
        public bool Success { get; set; }
        /// <summary>
        /// 返回数据
        /// </summary>
        [AliasAs("items")]
        public TResult Items { get; set; }
    }

    /// <summary>
    /// 返回的分页信息
    /// </summary>
    public class Page
    {
        /// <summary>
        /// 每页最大数据量
        /// </summary>
        [AliasAs("size")]
        public int MaxResultCount { get; set; }
        /// <summary>
        /// 符合条件的数据条数
        /// </summary>
        [AliasAs("totalElements")]
        public int TotalCount { get; set; }
        /// <summary>
        /// 符合条件的数据分页后的总页数
        /// </summary>
        [AliasAs("totalPages")]
        public int TotalPages { get; set; }
        /// <summary>
        /// 外部系统传入的GET参数的当前页码
        /// </summary>
        [AliasAs("number")]
        public int SkipCount { get; set; }
    }

    public static class AjaxResponseExtensions
    {
        /// <summary>
        /// 验证并返回结果
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="ajaxResponse"></param>
        /// <returns></returns>
        public static TResult ToResult<TResult>(this AjaxResponse<TResult> ajaxResponse)
        {
            if (ajaxResponse.Code != 200)
            {
                //throw new AbpException(ajaxResponse.Items);
            }
            return ajaxResponse.Items;
        }
    }
}
